/**
 * Eclipse Outliner
 * Copyright (C) 2006 Jeff Mesnil
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. 
 */
package net.jmesnil.opml.core.tests;

import junit.framework.TestCase;
import net.jmesnil.opml.core.IBody;
import net.jmesnil.opml.core.IOPML;
import net.jmesnil.opml.core.IOutline;
import net.jmesnil.opml.core.OPMLPlugin;

public class OutlineNextSiblingTestCase extends TestCase {

    private IBody body;

    protected void setUp() throws Exception {
        super.setUp();
        IOPML opml = OPMLPlugin.getDefault().createOPML();
        body = opml.getBody();
        assertNotNull(body);
    }

    protected void tearDown() throws Exception {
        body = null;
        super.tearDown();
    }

    public void testGetNextSiblingReturnsNullWithOnlyOneRootOutline()
            throws Exception {
        assertEquals(0, body.getChildren().length);
        IOutline outline = body.appendNewOutline("test");
        assertEquals(1, body.getChildren().length);
        IOutline nextSibling = outline.getNextSibling();
        assertNull(nextSibling);
    }

    public void testGetNextSiblingWithTwoRootOutlines() throws Exception {
        assertEquals(0, body.getChildren().length);
        IOutline firstOutline = body.appendNewOutline("first");
        IOutline secondOutline = body.appendNewOutline("second");
        assertEquals(2, body.getChildren().length);
        assertNull(secondOutline.getNextSibling());
        assertEquals(secondOutline, firstOutline.getNextSibling());
    }
    
    public void testGetNextSiblingReturnsNullWithOnlyOneOutline()
            throws Exception {
        assertEquals(0, body.getChildren().length);
        IOutline rootOutline = body.appendNewOutline("1");
        IOutline firstOutline = rootOutline.appendNewOutline("1.1");
        assertEquals(1, rootOutline.getChildren().length);
        IOutline nextSibling = firstOutline.getNextSibling();
        assertNull(nextSibling);
    }
    
    public void testGetNextSiblingWithTwoNonRootOutlines() throws Exception {
        assertEquals(0, body.getChildren().length);
        IOutline rootOutline = body.appendNewOutline("1");
        IOutline firstOutline = rootOutline.appendNewOutline("1.1");
        IOutline secondOutline = rootOutline.appendNewOutline("1.2");
        assertEquals(2, rootOutline.getChildren().length);
        assertNull(secondOutline.getNextSibling());
        assertEquals(secondOutline, firstOutline.getNextSibling());
    }
}
